package com.personnel.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.personnel.entity.YgUser;
import com.personnel.service.IYgUserService;
import com.personnel.service.YgUserService;

/**
 * Servlet implementation class AddYgUserServlet
 */
@WebServlet("/add.do")
public class AddYgUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddYgUserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		
		String ygbh = request.getParameter("ygbh");
		String ygxm = request.getParameter("ygxm");
		String ygxb = request.getParameter("ygxb");
		String csny = request.getParameter("csny");
		String zgxe = request.getParameter("zgxe");
		String zgxw = request.getParameter("zgxw");
		String byyx = request.getParameter("byyx");
		String wyzl = request.getParameter("wyzl");
		String wynl = request.getParameter("wynl");
		String sfzh = request.getParameter("sfzh");
		String ygxs = request.getParameter("ygxs");
		String bm_id = request.getParameter("bm_id");
		String g_id = request.getParameter("g_id");
		String hyzk = request.getParameter("hyzk");
		String zzmm = request.getParameter("zzmm");
		String mz = request.getParameter("mz");
		String jg = request.getParameter("jg");
		String lxdh = request.getParameter("lxdh");
		
		YgUser x = new YgUser();
		
		x.setYgbh(Integer.parseInt(ygbh));
		x.setYgxm(ygxm);
		x.setYgxb(Integer.parseInt(ygxb));
		x.setCsny(csny);
		x.setZgxe(zgxe);
		x.setZgxw(zgxw);
		x.setByyx(byyx);
		x.setWyzl(wyzl);
		x.setWynl(wynl);
		x.setSfzh(sfzh);
		x.setYgxs(ygxs);
		x.setBm_id(Integer.parseInt(bm_id));
		x.setG_id(Integer.parseInt(g_id));
		x.setHyzk(hyzk);
		x.setZzmm(zzmm);
		x.setMz(mz);
		x.setJg(jg);
		x.setLxdh(lxdh);
		
		IYgUserService service = new YgUserService();
		try {
			boolean isOkay = service.addYg(x);
			if(isOkay) {
				System.out.println("成功");
				response.sendRedirect("list.do");
			}else {
				System.out.println("Oh NO~");
				response.sendRedirect("module2/ruzhibiao.html");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
